function drawline(id, params) {
    var ele = document.getElementById(id);
    var bodywidth = $(document.body).width();
    var elewidth = bodywidth - 250;
    var eleheight = elewidth * 0.2;
    $(ele).css('width', elewidth+'px');
    $(ele).css('height', eleheight+'px');

    var myChart = echarts.init(ele);
    var option = {
        title : {
            text: params.title,//'某楼盘销售情况',
            subtext: params.subtitle,//'纯属虚构'
        },
        tooltip : {
            trigger: 'axis'
        },
        legend: params.legend,
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: false, readOnly: false},
                magicType : {show: false, type: ['line', 'bar', 'stack', 'tiled']},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        tooltip : {
            trigger: 'axis',
            show:true,
            showDelay: 0,
            transitionDuration:0,
            textStyle : {
                color: '#fff',
                decoration: 'none',
                fontSize: 12
            }
        },
        calculable : true,
        xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                data : params.xType,
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : params.valuelist
    };
    myChart.setOption(option);
}
//数组排序
function sortArray(data, sortid, sorttype) {
    var tmpArray = [],result = [];
    if(typeof data == 'object') {
        //处理数据
        for(var key in data) {
            tmp = data[key];
            tmp['pkey'] = key;
            if(sortid != 'pkey') {
                if(typeof data[key][sortid] != 'undefined') {
                    tmp[sortid] = parseInt(data[key][sortid]);
                } else {
                    tmp[sortid] = 0;
                }

            }
            tmpArray.push(tmp);
        }
        //排序
        for(var i = 0; i < tmpArray.length - 1 ; i ++) {
            for(var j = i + 1; j < tmpArray.length; j ++) {
                var i_item = tmpArray[i][sortid];
                var j_item = tmpArray[j][sortid];
                if(sorttype == 'asc' && i_item > j_item) {
                    tmpArray.splice(i, 0, tmpArray[j]);
                    tmpArray.splice(j + 1, 1);
                } else if(sorttype == 'desc' && i_item < j_item){
                    tmpArray.splice(i, 0, tmpArray[j]);
                    tmpArray.splice(j + 1,1);
                }
            }
        }
        //返回数据
        for(var i = 0; i < tmpArray.length;  i++) {
            var key = tmpArray[i]['pkey'];
            result["'"+key+"'"] = tmpArray[i];
        }
    }
    return result;
}

function getDateStr(){
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var yesterday = date.getDate() - 1;
    var weekbefore = date.getDate() - 7;
    var yesterday_date = new Date(year,month-1,yesterday);
    var weekbefore_date = new Date(year,month-1,weekbefore);
    var yweek = yesterday_date.getDay();
    var week = weekbefore_date.getDay();
    var yweekstr = "";
    switch(yweek){
        case 1:
            yweekstr = "周一";
            break;
        case 2:
            yweekstr = "周二";
            break;
        case 3:
            yweekstr = "周三";
            break;
        case 4:
            yweekstr = "周四";
            break;
        case 5:
            yweekstr = "周五";
            break;
        case 6:
            yweekstr = "周六";
            break;
        case 0:
            yweekstr = "周日";
            break;
        default:
            break;
    }
    switch(week){
        case 1:
            weekstr = "周一";
            break;
        case 2:
            weekstr = "周二";
            break;
        case 3:
            weekstr = "周三";
            break;
        case 4:
            weekstr = "周四";
            break;
        case 5:
            weekstr = "周五";
            break;
        case 6:
            weekstr = "周六";
            break;
        case 0:
            weekstr = "周日";
            break;
        default:
            break;
    }
    return  year + '-' + month + '-' + weekbefore + ' ' + weekstr + ' ~ ' +  year + '-' + month + '-' + yesterday + ' '+ yweekstr;
}
function getWeek(date){
    var week = date.getDay();
    switch(week){
        case 1:
            weekstr = "周一";
            break;
        case 2:
            weekstr = "周二";
            break;
        case 3:
            weekstr = "周三";
            break;
        case 4:
            weekstr = "周四";
            break;
        case 5:
            weekstr = "周五";
            break;
        case 6:
            weekstr = "周六";
            break;
        case 0:
            weekstr = "周日";
            break;
        default:
            break;
    }
    return weekstr;
}
function getDateWeek(){
    var begin_date,end_date;
    begin_date = $('#datepicker_begin').val();
    end_date = $('#datepicker_end').val();
    var yesterday_date = new Date(end_date);
    var weekbefore_date = new Date(begin_date);
    var yweek = getWeek(yesterday_date);
    var week = getWeek(weekbefore_date);
    return begin_date + " " + week + " ~ " + end_date +" "+  yweek;
}